package club.justwill.single.persistence.store;

import club.justwill.single.persistence.document.UserAdvice;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by luoyu on 2/22/16.
 */
@Component
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public class UserAdviceStore extends MongoDbStore<UserAdvice> {
    public UserAdvice getByUserId(Long userId) {
        return mongoTemplate.findOne(Query.query(Criteria.where("userId").is(userId)),UserAdvice.class);
    }


    public List<UserAdvice> getByPage(int index, int size) {
        Query query = new Query();
        query.skip(index);
        query.limit(size);
        List<UserAdvice> userAdviceList = mongoTemplate.find(query,UserAdvice.class);
        return userAdviceList;
    }
}
